#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Maxn=1e5+7,inf=1e9;
int Q;
int s[Maxn];

int main(){
	freopen("love.in","r",stdin);
	freopen("love.out","w",stdout);
	scanf("%d",&Q);
	int c=0;
	while(Q--){
		int opt;
		scanf("%d",&opt);
		
		if(opt==1){
			int f,t,b;
			cin>>f>>t>>b;
			s[++c]=f+b;
		}
		else{
			int p;
			cin>>p;
			s[p]=-inf;
		}
		sort(s+1,s+c+1);
		int l=1;
		for(int i=1;i<=c;i++) if(s[i]!=-inf){
			l=i;break;
		} 
		int ret=s[(l+c)/2];
		ll sm=0;
//		cout<<s[(l+c)/2]<<endl;
		for(int i=l;i<=c;i++) sm+=abs(s[i]-ret);
		cout<<sm<<endl;
	}
	return 0;
}

